﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using WeiboFilter.DAL;
using WeiboFilter.Models;
using WeiboFilter.SinaWeibo;

namespace WeiboFilter
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //login successfully
            if (Session["oauth_token"] != null)
            {
                Response.Redirect("Default.aspx");
            }

        }

        protected void imgLogin_Click(object sender, ImageClickEventArgs e)
        {
            oAuthSina oauth = new oAuthSina();
            oauth.RequestTokenGet();
            string url = oauth.AuthorizationGet();
            Session["oauth_token"] = oauth.token;
            Session["oauth_token_secret"] = oauth.tokenSecret;
            Response.Redirect(url + "&oauth_callback=http://localhost:3374/Default.aspx");
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            CustomerDAL cD = new CustomerDAL();
            Customer c = cD.GetCustomerById(txtUserId.Text);

            if (c.c_pwd.Trim() != txtPwd.Text.Trim())//验证控件需要后续添加
            {
                Response.Write("<script>alert('密码错误或没有此用户！');</script>");
            }
            else
            {
                Session["customer"] = c.c_id;
                Response.Redirect("Default.aspx");
            }

        }
    }
}